using System;
using System.Collections.Generic;
using System.Text;
using AllegNet;

namespace DemonHunter
{
    /// <summary>
    /// NOTE:
    /// due to the nature of games and concerning their performance some values must be
    /// known ahead of time and hardcoded, such as the location of bitmaps for an entity.
    /// All bitmaps must be loaded into memory ahead of time and an entity must know where to find
    /// itself.  Therefore all index values pertinent to that entity will be hardcoded and should
    /// be assumed that they are referring to the levelBitmap array in level.
    /// </summary>
    abstract class Entity
    {
        //data
        protected double entityXLoc;
        protected double entityYLoc;

        protected int health = 5;
        protected bool killable = false;

        protected static double speedModifier;

        //virtual methods
        public virtual void moveRight()
        {
            entityXLoc += (3 * speedModifier);
        }

        public virtual void moveLeft()
        {
            entityXLoc -= (2 * speedModifier);
        }

        public virtual void moveUp()
        {
            if (entityYLoc + GetCurrentBitmapHeight() > 585) entityYLoc -= (.5 * speedModifier);
        }

        public virtual void moveDown() 
        {
            if (entityYLoc + GetCurrentBitmapHeight() < 650) entityYLoc += (.5 * speedModifier);
        }

        public virtual void move()
        {
            PlayerCharacter player = PlayerCharacter.GetInstance();

            if (entityXLoc < player.getEntityXLoc()) moveRight();
            if (entityYLoc + GetCurrentBitmapHeight() < player.getEntityYLoc() + player.GetCurrentBitmapHeight()) moveDown();
            else if (entityYLoc + GetCurrentBitmapHeight() > player.getEntityYLoc() + player.GetCurrentBitmapHeight()) moveUp();
        }

        public virtual void ReduceHealth(int amt)
        {
            if (!killable) return;
            health -= amt;
            if (health <= 0) KillMe();
        }

        protected virtual void KillMe()
        {
            Level.GetInstance().RemoveEntity(this);
        }

        public abstract void animate();

        //setters
        public void setEntityXLocation(double xLoc)
        {
            entityXLoc = xLoc;
        }
        public void setEntityYLocation(double yLoc)
        {
            entityYLoc = yLoc;
        }
        //methods
        public abstract Bmp GetCurrentBitmap();

        public double getEntityYLoc()
        {
            return entityYLoc;
        }
        public double getEntityXLoc()
        {
            return entityXLoc;
        }

        public static void LoadBitmaps() { }

        public static void setSpeedModifier(double modifier) { speedModifier = modifier; }

        virtual public void DoXIncrease() { entityXLoc += 3 * speedModifier; }

        public abstract double GetCurrentBitmapHeight();

        public bool IsKillable() { return killable; }
    }
}
